﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AutoPartsSearch.Domain.Abstract;
using AutoPartsSearch.Domain.Abstract.Repositories;
using AutoPartsSearch.Domain.Entities;
using AutoPartsSearch.Domain.Entities.Messages;

namespace AutoPartsSearch.Domain.Concrete
{
    public class OfferProcessor : IOfferProcessor
    {
        private readonly string _newOffer = "our offer {0}";

        private ISearchQueryRepository _searchQueryRepository;
        private ISellerRepository _sellerRepository;
        private IMessageSender _messageSender;
        private ISellerSearchQueryRepository _sellerSearchQueryRepository;
        private IMessageBuilder _messageBuilder;

        public OfferProcessor(ISearchQueryRepository searchQueryRepository
            , ISellerRepository sellerRepository
            , IMessageSender messageSender
            , ISellerSearchQueryRepository sellerSearchQueryRepository
            , IMessageBuilder messageBuilder)
        {
            this._searchQueryRepository = searchQueryRepository;
            this._sellerRepository = sellerRepository;
            this._messageSender = messageSender;
            this._sellerSearchQueryRepository = sellerSearchQueryRepository;
            this._messageBuilder = messageBuilder;
        }

        public void Process(Offer offer)
        {
            var searchQuery = _searchQueryRepository.GetById(offer.QueryId);
            var seller = _sellerRepository.GetById(offer.SellerId);
            var message = _messageBuilder.BuildOffer(searchQuery, seller, offer);
            this._messageSender.Send(message);
            this._sellerSearchQueryRepository.MarkAsProcessed(searchQuery.Id, seller.Id);
        }
    }
}
